package com.mall.controller;

import com.mall.common.R;
import com.mall.entity.LoginUser;
import com.mall.entity.SmoothMallCart;
import com.mall.entity.dto.SmoothMallCartDto;
import com.mall.service.Impl.SmoothMallCartServiceImpl;
import com.mall.service.SmoothMallCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SmoothMallCartController {
    @Autowired
    SmoothMallCartService smoothMallCartService;
    @PostMapping("/cart/add/{productId}/{count}")
    public R addForCart(@PathVariable Integer productId,@PathVariable Integer count){
        boolean b = smoothMallCartService.addToCart(productId, count);
        if (b){
            return R.success("yes");
        }
        return R.error("添加失败");
    }
    @GetMapping("/cart/list")
    public List<SmoothMallCartDto> getList(){
        return smoothMallCartService.getListByUserId();
    }
    @DeleteMapping("/cart/delete/{productId}")
    public R deleteCart(@PathVariable Integer productId){
        boolean b = smoothMallCartService.deleteCart(productId);
        if (b){
            return R.success("删除成功！");
        }else {
            return R.error("删除失败！");
        }
    }
    @PostMapping("/cart/select/{productId}/{selectId}")
    public R selectForCart(@PathVariable Integer productId,@PathVariable Integer selectId){
        List<SmoothMallCartDto> smoothMallCartDtos = smoothMallCartService.selectForCart(productId, selectId);
        return R.success(smoothMallCartDtos);
    }
}
